Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

embed-json

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

embed-json

Inline/Embed JSON data from files into HTML.

  • 1.2.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

embed-json

Node.js module to inline/embed JSON data from files into html.

NPM

npm version

CircleCI

Installation

NPM

npm i --save embed-json

Yarn

yarn add embed-json

Usage

Synopsis

embedJson(htmlString, options);

Embed JSON data from referenced files into the given HTML string.

When embedJson() encounters a script tag with JSON mime type and a src attribute with htmlString, e.g.

<script type="application/json" src="data.json"></script>

it will retrieve the data from the file src and embed it into the tag. The src attribute is removed during this operation.

Example

const embedJson = require('embed-json');
const fs = require('fs');

const html = fs.readFileSync('index.html', 'utf8');
const htmlWithEmbeddedJSON = embedJson(html);
// script tags with src attribute in index.html
// <script type="application/json" src="data.json"></script>
// are transformed to
// <script type="application/json">{dataThat:'was in data.json'}</script>

Options

encoding string

Default: utf8

Specify the encoding of the JSON files.

mimeTypes Array<string> | string

Default: ['application/json', 'application/ld+json']

Specify the mime type(s) of scripts to embed.

minify boolean

Default: true

Specify whether or not to minify the embedded JSON data.

root string

Default: path.dirname(require.main.filename) (i.e. a best guess at the project root.)

Specify the root directory from which to resolve relative srcs.

Changelog

License

Keywords

FAQs

Package last updated on 11 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc